<html>
<head>
<script type="text/javascript" src="jquery-2.1.4.min.js"></script>
<script type="text/javascript">
var dtd = $.Deferred(); // create a deferred object
var wait = function(dtd) {
	var tasks = function() {
		alert("over!");
		dtd.resolve(); // change the state of the deferred object from pending to resolved
	};
	setTimeout(tasks, 50000);
	return dtd;
};

$.when(wait(dtd))
	.done(function(){ alert("success!"); })
	.fail(function(){ alert("error!"); });

alert(123);

</script>
</head>

<body>
nihao
</body>
</html>